Ext.define('TS.controller.Dilema', {
	extend: 'Ext.app.Controller',

	models: [// TODO zgrupowac słowniki z kodami (do słownika)
		'Dilema','DilemaPoint','DilemaTag',
		'DilemaPointRate','DilemaPointMovie','DilemaPointQuote','DilemaPointCounterpoint'
	],
	stores: [
	    'Dilema','DilemaPointYes','DilemaPointNo','DilemaTag',
	    'DilemaPointRate','DilemaPointMovie','DilemaPointQuote','DilemaPointCounterpoint'
	],
	views: [
		'dilema.Panel'
	],
	
	init: function() {
		this.control({
			'viewport > tabpanel' : {
               render: this.onStart,
               tabchange:this.onShow
            }
		});
	},
	
	onStart:function(tabpanel,x){
		tabpanel.add({xtype:'dilemapanel'});
	},
	
	onShow:function(tabpanel,tab){

		if(tab.xtype=='dilemapanel' && tab.items.length==0){

			Util.require([
			      'Grid','Form','PointGrid','PointForm','TagForm','TagGrid',
			      //'Rate','Movie','Quote','Counterpoint',
			      'RateGrid','RateForm',
			      'MovieGrid','MovieForm','#movie.movie.Form',
			      'QuoteGrid','QuoteForm',
			      'CounterpointGrid', 'CounterpointForm'
			      
			],function(){
				tab.add(
					//Factory.layout.duoTab('Dylematy','dilema','left'),
					{layout:'border',dockedItems:[
																
						{
							xtype:'panel',
							dock:'right',
							
							layout:'accordion',
							width:CONST.width.third,
							tbar:[{xtype:'dilemapointform',width:CONST.width.third-5}],
							items:[
								{xtype:'dilemapointquotegrid',title:'Cytaty'},
								{xtype:'dilemapointmoviegrid',title:'Filmy'},
								{xtype:'dilemapointcounterpointgrid',title:'Kontrargumenty'},
								{xtype:'dilemapointrategrid',title:'Oceny'}
							]
						}
					],title:'Dylematy',items:[
						{xtype:'dilemagrid',region:'center',dockedItems:[

						
						]},
						
						{region:'east',width:CONST.width.third,layout:'border',items:[
							{xtype:'dilemapointgrid',title:'Tak',name:'yes',store:'DilemaPointYes',region:'center'},
							{xtype:'dilemapointgrid',title:'Nie',name:'no',store:'DilemaPointNo',region:'east'}
						],dockedItems:[
							{xtype:'dilemaform',docked:'top'},
							{xtype:'dilemataggrid',docked:'bottom',height:80, hideHeaders:0}
						]}
					]}
			
				);
				Util.s.fillEach(Dict.testament,Dict.movie,
					Dict.tag,Dict.argument,Dict.author,Dict.language,Dict.book,Dict.chapter
				);
				
			},'TS.view.dilema');			
		};
	},
	
	util:{
		
	}
});